//
//  CharTableViewCell.m
//  6.10.QQ
//
//  Created by lovena on 15/6/11.
//
//

#import "CharTableViewCell.h"
#import "UIImage+MJ.h"
@implementation CharTableViewCell

+(id)initWithChar:(UITableView *)tableView
{
    //三步
    static NSString *ID=@"cell";
    CharTableViewCell *cell=[tableView dequeueReusableCellWithIdentifier:ID];
    if(cell==nil)
    {
        cell=[[CharTableViewCell alloc]initWithStyle:UITableViewCellStyleDefault reuseIdentifier:ID];
    }
    return cell;
}
//重写构造方法
-(id)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier
{
    if(self==[super initWithStyle:style reuseIdentifier:reuseIdentifier])
    {
        //创建头像
        UIImageView *image=[[UIImageView alloc]init];
        //头像的角度设置
        image.layer.cornerRadius=8;
        image.clipsToBounds=YES;
        [self.contentView addSubview:image];
        self.image=image;
        //时间标签
        UILabel *label=[[UILabel alloc]init];
        //字体大小
        label.font=[UIFont systemFontOfSize:14];
        //颜色
        label.textColor=[UIColor grayColor];
        label.textAlignment=NSTextAlignmentCenter;
        [self.contentView addSubview:label];
        self.timeLabel=label;
        
        //对话框
        UIButton *btn=[[UIButton alloc]init];
        //按钮的标题
        btn.titleLabel.font=[UIFont systemFontOfSize:15];
        btn.titleLabel.numberOfLines=0;
        [self.contentView addSubview:btn];
        self.textBtn=btn;
        
        // 背景色为空，显示表的背景
        self.backgroundColor=[UIColor clearColor];
    }
    return self;
}
//重写set方法
-(void)setMessageset:(XQMessageSet *)messageset
{
    _messageset=messageset;
    //给内容
    XQMessage *mess=messageset.message;
    //时间
    if(mess.timeHidden)
    {
        self.timeLabel.hidden=YES;
    }
    else
    {
        self.timeLabel.hidden=NO;
        self.timeLabel.text=mess.time;
        self.timeLabel.frame=messageset.timeF;
    }
    //头像
//    if(mess.type==MessageMe)
//    {
//        self.image.image=[UIImage imageNamed:@"me"];
//    
//    }
//    else
//    {
//        self.image.image=[UIImage imageNamed:@"other"];
//    }
    self.image.image=[UIImage imageNamed:(mess.type==MessageMe)?@"me":@"other"];
    self.image.frame=messageset.iconF;
    //对话框
    [self.textBtn setTitle:mess.text forState:UIControlStateNormal];
    self.textBtn.frame=messageset.textF;
    //对话框背景色
    NSString *normal,*high;
    if(mess.type==MessageMe)
    {
        normal = @"chat_send_nor";
        high = @"chat_send_press_pic";

        [self.textBtn setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
    }
    else
    {
        normal = @"chat_recive_nor";
        high = @"chat_recive_press_pic";
        [self.textBtn setTitleColor:[UIColor blackColor] forState:UIControlStateNormal];
    }
    self.textBtn.contentEdgeInsets=UIEdgeInsetsMake(15, 20, 15, 20);
    [self.textBtn setBackgroundImage:[UIImage resizedImageNamed:normal] forState:UIControlStateNormal];
    [self.textBtn setBackgroundImage:[UIImage resizedImageNamed:high] forState:UIControlStateHighlighted];
}
@end
